<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>自定义帖子管理</title>
<link rel="stylesheet" href="/layui/css/layui.css"></link>
<link rel="stylesheet" href="/css/css.css"></link>
</head>
<body>

<div style="padding: 20px">
	        <span class="layui-breadcrumb">
			  <a>首页</a>
			  <a><cite>自定义帖子管理</cite></a>
			</span>
	<div style="padding-top: 20px;">
		<div>
			<div>
				<button class="layui-btn layuiadmin-btn-list" data-type="batchdel" onclick="addArticle()">添加</button>
			</div>
		</div>
		<div>
			<table width="100%" id="articleListTable" ></table>
		</div>
	</div>
</div>

<script src="/layui/layui.js"></script>
<script src="/js/jquery.js"></script>
<script src="/js/common.js"></script>
<script type="text/javascript">

    layui.use(['element','form','table'], function(){
        var form=layui.form;
        var element = layui.element; //导航的hover效果、二级菜单等功能，需要依赖element模块
        $ = layui.jquery; // 使用jquery
        table = layui.table;

        table.render({
            elem: '#articleListTable'
            ,url:'/admin/article/list'
            ,cols: [[
                {type:'checkbox'}
                ,{field:'id', width:100,title: '编号'}
                ,{field:'title', title: '自定义帖子名称'}
                ,{field:'action', width:300, title: '操作',align:'center',templet:formatAction}
            ]]
            ,page: true
        });


    });


    function deleteOne(id){
        layer.confirm('您确定要删除这条记录吗？', {
            title:"系统提示"
            ,btn: ['确定','取消'] //按钮
        }, function(){
            layer.closeAll('dialog');
            $.post("/admin/article/delete",{"id":id},function(result){
                if(result.success){
                    layer.msg("删除成功！");
                    table.reload("articleListTable",{});
                }else{
                    layer.msg("删除失败，请联系管理员！");
                }
            },"json");
        }, function(){

        });
    }

    function addArticle(){
        layer.open({
            type: 2,
            title: '添加自定义帖子',
            area: ['1000px', '730px'],
            content: '/admin/saveArticle.html' //iframe的url
        });
    }

    function modifyArticle(id){
        layer.open({
            type: 2,
            title: '修改自定义帖子',
            area: ['1000px', '730px'],
            content: '/admin/saveArticle.html?id='+id //iframe的url
        });
    }


    function formatAction(d){
        return "<a class='layui-btn layui-btn-danger layui-btn-xs' target='_blank' href='/article/"+d.id+"'><i class='layui-icon layui-icon-read'></i>帖子预览</a><button class='layui-btn layui-btn-normal layui-btn-xs' onclick='modifyArticle("+d.id+")'><i class='layui-icon layui-icon-edit'></i>编辑</button><button class='layui-btn layui-btn-warm layui-btn-xs' onclick='deleteOne("+d.id+")'><i class='layui-icon layui-icon-delete' ></i>删除</button>";
    }



</script>
</body>
</html>